package com.aiton.bamin.bamindaijiadrier.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aiton.bamin.bamindaijiadrier.R;
import com.aiton.bamin.bamindaijiadrier.model.Bill;
import com.aiton.bamin.bamindaijiadrier.model.User;

import java.text.SimpleDateFormat;
import java.util.List;


/**
 * 账单
 */
public class MyBillAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private List<Bill.ResultsBean> rechargeLogContains;
    private User mUser;

    public MyBillAdapter(Context context, List<Bill.ResultsBean> rechargeLogContains) {
        inflater = LayoutInflater.from(context);

        this.rechargeLogContains = rechargeLogContains;
    }

    class ViewHolder {
        TextView textView_type;
        TextView textView_Time;
        TextView tv_bill_plus_title;
        TextView tv_bill_plus_money;
        TextView tv_bill_minus_title;
        TextView tv_bill_minus_money;
        TextView tv_bill_status;
        View line_bill_plus;
        View line_bill_minus;

    }

    @Override
    public int getCount() {
        return rechargeLogContains.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_bill, null);
            holder.textView_type = (TextView) convertView.findViewById(R.id.textView_type);
            holder.textView_Time = (TextView) convertView.findViewById(R.id.textView_Time);
            holder.tv_bill_plus_title = (TextView) convertView.findViewById(R.id.tv_bill_plus_title);
            holder.tv_bill_plus_money = (TextView) convertView.findViewById(R.id.tv_bill_plus_money);
            holder.tv_bill_minus_title = (TextView) convertView.findViewById(R.id.tv_bill_minus_title);
            holder.tv_bill_minus_money = (TextView) convertView.findViewById(R.id.tv_bill_minus_money);
            holder.tv_bill_status = (TextView) convertView.findViewById(R.id.tv_bill_status);
            holder.line_bill_plus =  convertView.findViewById(R.id.line_bill_plus);
            holder.line_bill_minus = convertView.findViewById(R.id.line_bill_minus);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Bill.ResultsBean resultsBean = rechargeLogContains.get(position);

        holder.textView_Time.setText("时间："+ resultsBean.getTime());
        holder.textView_type.setText("类型："+ resultsBean.getModel());
        holder.tv_bill_status.setText("状态："+ resultsBean.getStatus());
        if(TextUtils.equals(resultsBean.getModel(),"提现")){
            holder.line_bill_plus.setVisibility(View.GONE);
            holder.tv_bill_minus_title.setText("个人");
            Integer money = resultsBean.getMoney();
            CharSequence replace = TextUtils.replace(money + "", new String[]{"-"}, new String[]{""});
            holder.tv_bill_minus_money.setText(replace);
        }else if(TextUtils.equals(resultsBean.getModel(),"代驾")){
            holder.tv_bill_plus_money.setText(resultsBean.getDriverMoney()+"");
            holder.tv_bill_minus_money.setText(resultsBean.getSystemMoney()+"");
        }

        return convertView;
    }
}